package com.bluemoon.daps.test.sync.v1_3.model2dev;

import cn.com.bluemoon.daps.common.domain.UserInfoHolder;
import cn.com.bluemoon.daps.common.enums.SyncStatus;
import cn.com.bluemoon.daps.common.enums.SyncToEnv;
import cn.com.bluemoon.daps.common.exception.DapException;
import cn.com.bluemoon.daps.common.toolkit.BmAssetUtils;
import cn.com.bluemoon.daps.sync.DapsSyncApplication;
import cn.com.bluemoon.daps.sync.entity.DapSyncDevEnvTask;
import cn.com.bluemoon.daps.sync.service.DapModel2DevSyncService;
import cn.com.bluemoon.daps.sync.vo.model2dev.SyncTableInfoOut;
import cn.com.bluemoon.daps.sync.vo.model2dev.SyncTablePageVo;
import cn.com.bluemoon.daps.sync.vo.model2dev.SyncTableTaskOut;
import cn.com.bluemoon.daps.sync.vo.model2dev.SyncTableTaskPageVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collections;

/**
 * @author Jarod.Kong
 * @date 2021/6/17 14:55
 */
@SpringBootTest(classes = DapsSyncApplication.class)
@RunWith(value = SpringRunner.class)
@Slf4j
public class Model2DevV3 {
    String modelId = "1409789077630291969";

    @Autowired
    private DapModel2DevSyncService model2DevSyncService;


    @Test
    public void test_1() {
        SyncTablePageVo pageVo = new SyncTablePageVo();
        pageVo.setKeyword("test");
        pageVo.setDevStatus(SyncStatus.SYNC_WAIT);
        pageVo.setTestStatus(null);
        pageVo.setModelId(modelId);
        IPage<SyncTableInfoOut> SyncTableInfoOutIPage = model2DevSyncService.querySyncList(pageVo);
        BmAssetUtils.isTrue(SyncTableInfoOutIPage.getRecords().isEmpty());
        pageVo.setKeyword("model");
        pageVo.setDevStatus(null);
        pageVo.setTestStatus(null);
        SyncTableInfoOutIPage = model2DevSyncService.querySyncList(pageVo);
        BmAssetUtils.isTrue(!SyncTableInfoOutIPage.getRecords().isEmpty());
    }

    @Test
    public void test_add_() {
        DapSyncDevEnvTask task = new DapSyncDevEnvTask();
        task.setTableId("");
        task.setModelId(modelId);

    }

    @Test
    public void test_2() {
        String s = model2DevSyncService.viewSyncTaskLog("1");
        String s1 = model2DevSyncService.viewSyncTaskLog("2");
        System.out.println();
    }

    @Test
    public void test_3() {
        SyncTableTaskPageVo vo = new SyncTableTaskPageVo();
        vo.setModelId(modelId);
        vo.setTableId("1405456911576449026");
        vo.setType(1);
        IPage<SyncTableTaskOut> tasks = model2DevSyncService.viewSyncTasks(vo);
        System.out.println(tasks);
    }

    @Test
    public void test_4() {
        try {
            model2DevSyncService.async(modelId, SyncToEnv.TEST, Collections.emptyList(), UserInfoHolder.getUserInfoOrEmpty());
            System.out.println();
        } catch (DapException e) {
            // nothing
        }
    }

//
//
//    @Test
//    public void test_api_1() {
//        List<CompareResult<DevModelCompareResult>> compareResults = syncService.compareDevAndModelTables2DB(modelId);
//        log.info("{}", compareResults);
//    }
}
